package com.Archive.secondWeek;

public class Max_Sort {
    public int max(int[] arr){
        int Cache = arr[0];
        for(int c:arr){
            if(Cache<c){
                Cache = c;
            }
        }return Cache;
    }
    public int[] sort(int[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            for(int j = i +1;j<arr.length;j++){
                if(arr[i]>arr[j]){
                    int intCache = arr[i];
                    arr[i]=arr[j];
                    arr[j]=intCache;
                }
            }
        }return arr;
    }

    public static void main(String[] args) {
        Max_Sort m = new Max_Sort();
        int[] arr = new int[]{2,1,5,9,12,31,11,56,-4};
        System.out.println("数组中的最大值为："+m.max(arr));
        System.out.println("数组从大到小排序为：");
        for(int p:m.sort(arr)){
            System.out.print(p+"\t");
        }
    }
}
